<template>
	<view>
		<web-view :src="externalPageUrl" :update-title="isUpdateTitle" @message="getMessage"></web-view>
	</view>
</template>

<script>
	// 小程序仅支持加载网络网页，不支持本地html
	export default {
		onLoad(item) {
			this.externalPageUrl = decodeURIComponent(item.url)
			// 传入需要跳转的链接 使用web-view标签进行跳转

			if (this.externalPageUrl == 'https://www.cikeee.com/') {
				uni.setNavigationBarTitle({
					title: '一言'
				})
			} else if (this.externalPageUrl == '/hybrid/html/baiduMap/baiduMap.html') {
				uni.setNavigationBarTitle({
					title: '标准地图'
				})
			} else if (this.externalPageUrl == '/hybrid/html/baiduMap/baiduMapPro.html') {
				uni.setNavigationBarTitle({
					title: '个性地图'
				})
			} else if (this.externalPageUrl == '/hybrid/html/baiduMap/baiduMapTrack.html') {
				uni.setNavigationBarTitle({
					title: '轨迹动画'
				})
			} else if (this.externalPageUrl == '/hybrid/html/baiduMap/baiduMapSubway.html') {
				uni.setNavigationBarTitle({
					title: '地铁地图'
				})
			} else if (this.externalPageUrl == '/hybrid/html/baiduMap/baiMapLocation.html') {
				uni.setNavigationBarTitle({
					title: '地图定位'
				})
			} else if (this.externalPageUrl == '/hybrid/html/baiduMap/baiduMapTraffic.html') {
				uni.setNavigationBarTitle({
					title: '交通流量'
				})
			} else if (this.externalPageUrl == '/hybrid/html/baiduMap/baiduMapCluster.html') {
				uni.setNavigationBarTitle({
					title: '聚合图标'
				})
			} else if (this.externalPageUrl == encodeURIComponent('https://universal.u-cold.com:18443/video/#/?type=real&deviceId=1000011$1$0$64')) {
				uni.setNavigationBarTitle({
					title: '视频播放'
				})
			}
		},
		data() {
			return {
				externalPageUrl: '',
				isUpdateTitle: false
			}
		},
		onBackPress(event) {
			// 自定义返回事件
			uni.switchTab({
				url: '../business/index'
			});
			return true
		},
		methods: {
			// 获取 html 通过 uni.postMessage 传递过来的数据
			getMessage(event) {
				let receiveData = JSON.stringify(event.detail.data[0])
				// console.log(typeof(receiveData));
				uni.redirectTo({
					url: './dataReceive?point=' + receiveData
				});
			}
		}
	}
</script>

<style lang="scss"></style>
